package com.zuxia.mapper;

import com.github.pagehelper.Page;
import com.zuxia.dto.BookPageQueryDTO;
import com.zuxia.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {

    /**
     * 根据id查询图书数据
     * @param id
     * @return
     */
    @Select("select  * from tbl_book where id = #{id}")
    public Book getById(Integer id);

    /**
     * 查询所有图书数据
     */
    @Select("select  * from tbl_book")
    public List<Book> getAll();

    /**
     * 添加图书信息
     * @param book
     */
    @Insert("insert into tbl_book(id,type,name,description) " +
            "values " +
            "(#{id},#{type},#{name},#{description})")
    public Integer insert(Book book);

    /**
     * 修改图书信息
     * @param book
     * @return
     */
    @Update("update tbl_book set type=#{type},name=#{name},description=#{description} where id=#{id}")
    public Integer updateById(Book book);

    /**
     * 根据图书id删除图书信息
     * @param id
     * @return
     */
    @Delete("delete from tbl_book where id=#{id}")
    public Integer deleteById(Integer id);

    /**
     * 分页查询
     * @param bookPageQueryDTO
     * @return
     */
    public Page<Book> pageQuery(@Param("dto") BookPageQueryDTO bookPageQueryDTO);

}
